<html>
<head><meta charset="utf-8"><title>wtf codegen, again? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html">wtf codegen, again?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="150686820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wtf%20codegen%2C%20again%3F/near/150686820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html#150686820">(Dec 01 2018 at 15:15)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">define</span> <span class="k">i32</span> <span class="vg">@caller</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="nv nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i1</span> <span class="vg">@llvm.expect.i1</span><span class="p">(</span><span class="k">i1</span> <span class="k">false</span><span class="p">,</span> <span class="k">i1</span> <span class="k">false</span><span class="p">)</span>
  <span class="k">br</span> <span class="k">i1</span> <span class="nv nv-Anonymous">%0</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%panic.i</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%callee.exit</span>

<span class="nl">panic.i:</span>                                          <span class="c">; preds = %start</span>
<span class="c">; call core::panicking::panic</span>
  <span class="k">call</span> <span class="kt">void</span> <span class="vg">@_ZN4llvm9panicking5panic17h58fdea4fa7a9abc8E</span><span class="p">({</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*,</span> <span class="k">i64</span> <span class="p">},</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*,</span> <span class="k">i64</span> <span class="p">},</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i32</span><span class="p">],</span> <span class="k">i32</span><span class="p">,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i32</span><span class="p">],</span> <span class="k">i32</span><span class="p">,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i32</span><span class="p">]</span> <span class="p">}*</span> <span class="k">noalias</span> <span class="k">readonly</span> <span class="k">dereferenceable</span><span class="p">(</span><span class="m">40</span><span class="p">)</span> <span class="k">bitcast</span> <span class="p">({</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*,</span> <span class="k">i64</span> <span class="p">},</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*,</span> <span class="k">i64</span> <span class="p">},</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span> <span class="p">}*</span> <span class="vg">@panic_loc.2</span> <span class="k">to</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*,</span> <span class="k">i64</span> <span class="p">},</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*,</span> <span class="k">i64</span> <span class="p">},</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i32</span><span class="p">],</span> <span class="k">i32</span><span class="p">,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i32</span><span class="p">],</span> <span class="k">i32</span><span class="p">,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i32</span><span class="p">]</span> <span class="p">}*))</span>
  <span class="k">unreachable</span>

<span class="nl">callee.exit:</span>                                      <span class="c">; preds = %start</span>
  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%bb1</span>

<span class="nl">bb1:</span>                                              <span class="c">; preds = %callee.exit</span>
  <span class="k">ret</span> <span class="k">i32</span> <span class="m">8</span>
</pre></div>



<a name="150686864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wtf%20codegen%2C%20again%3F/near/150686864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html#150686864">(Dec 01 2018 at 15:16)</a>:</h4>
<p>does another run of <code>-instcombine -simplifycfg</code> clean that up?</p>



<a name="150686873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wtf%20codegen%2C%20again%3F/near/150686873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html#150686873">(Dec 01 2018 at 15:17)</a>:</h4>
<p>now that’s some weird codegen haha, though note that this occurs with <code>-Copt-level=0</code> only for code as such:</p>
<div class="codehilite"><pre><span></span><span class="cp">#[inline(always)]</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">callee</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">u32</span> <span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">4</span><span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">caller</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">u32</span> <span class="p">{</span><span class="w"> </span><span class="n">callee</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="150686939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wtf%20codegen%2C%20again%3F/near/150686939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html#150686939">(Dec 01 2018 at 15:19)</a>:</h4>
<blockquote>
<p>does another run of <code>-instcombine -simplifycfg</code> clean that up?</p>
</blockquote>
<p>I’m sure it would, but the point is that we end up with some weird IR <em>without</em> optimisations… well, I’ve been told we run inliner at <code>-Copt-level=0</code>, but still...</p>



<a name="150686987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wtf%20codegen%2C%20again%3F/near/150686987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html#150686987">(Dec 01 2018 at 15:20)</a>:</h4>
<p>Ok I thought this was after -O2 and thus a pass ordering issue. -O0 is weird (what's the assume for anyway?) but I could see it happening from a combinations of MIR optz not finishing the job and IRBuilder constant folding</p>



<a name="150687036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wtf%20codegen%2C%20again%3F/near/150687036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wtf.20codegen.2C.20again.3F.html#150687036">(Dec 01 2018 at 15:22)</a>:</h4>
<p>oh derp, expect, not assume, so it's expecting the integer overflow to not happen. and IRBuilder constant folds it to not happen, I guess</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>